<?php

namespace Common\Bundle\LibraryBundle\Form;

use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolverInterface;

class QuestionType extends AbstractType
{
    /**
     * @param FormBuilderInterface $builder
     * @param array $options
     */
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder
            ->add('libelle', 'text', array('attr' => array('class' => 'input-sm'),'required' => true))
            ->add('typeQuestion', null, array('required' => true, 'attr' => array('class' => 'input-sm')))
            ->add('aide', 'textarea', array('attr' => array('class' => 'input-sm'), 'required' => false))
            ->add('complementReponse', 'textarea', array('attr' => array('class' => 'input-sm'), 'required' => false))
            ->add('reponses', 'collection', array('type' => new ReponseType(),
                'allow_add'    => true,
                'allow_delete' => true,
                'prototype' => true,
                'prototype_name' => 'reponses_name',
                'cascade_validation' => true))
        ;
    }
    
    /**
     * @param OptionsResolverInterface $resolver
     */
    public function setDefaultOptions(OptionsResolverInterface $resolver)
    {
        $resolver->setDefaults(array(
            'data_class' => 'Common\Bundle\LibraryBundle\Entity\Question',
            'cascade_validation' => true
        ));
    }

    /**
     * @return string
     */
    public function getName()
    {
        return 'common_bundle_librarybundle_question';
    }
}
